<?php

namespace app\api\validate;


use app\common\enum\GoodsEnum;
use app\common\model\goods\Goods;
use app\common\validate\BaseValidate;

/**
 * 分享验证器
 * Class ShareValidate
 * @package app\shopapi\validate
 */
class ShareValidate extends BaseValidate
{
    protected $rule = [
        'id' => 'checkGoods',
        'page' => 'require',
    ];

    protected $message = [
        'page.require' => '路径缺失',
    ];

    public function sceneGetMnpQrCode()
    {
        return $this->only(['id','page']);
    }

    protected function checkGoods($value,$rule,$data)
    {
        $goods = Goods::where('id',$value)->findOrEmpty()->toArray();
        if(empty($goods)){
            return '商品不存在';
        }
        if(GoodsEnum::STATUS_STORE == $goods['status']){
            return '商品已下架';
        }
        return true;

    }
}